﻿<div class="page">
    <div id="header" class="bar">
        <div id="btnBack" class="btn-left">
            <span>Back</span>
        </div>
        <div id="btnUpload" class="btn-right">
            <span>Upload</span>
        </div>
    </div>
    <div id="content">
        <h1 id="lblTitle"></h1>
        <div id="lblContent">
            
        </div>
    </div>
    <div id="footer" class="bar">
        <ul class="nav3">
            <li id="btnEditTitle"><span>Edit Title</span></li>
            <li id="btnEditContent"><span>Edit Content</span></li>
            <li id="btnDelete"><span>Delete</span></li>
        </ul>
    </div>
</div>
<script language="javascript" type="text/javascript">
    (function () {
        var editingBlog = null;
        $(document).ready(function () {
            editingBlog = nova.application.currentPage.blog;
            $("#lblTitle").html(editingBlog.title);
            $("#lblContent").html(editingBlog.content);

            nova.touch.bindClick("#btnBack", function () {
                nova.application.goBack();
            });
            nova.touch.bindClick("#btnEditTitle", function () {
                var page = new nova.Page("pages/editTitle.html");
                page.blog = editingBlog;
                nova.application.gotoPage(page);
            });
            nova.touch.bindClick("#btnEditContent", function () {
                var page = new nova.Page("pages/editContent.html");
                page.blog = editingBlog;
                page.backToListPage = false;
                nova.application.gotoPage(page);
            });
            nova.touch.bindClick("#btnDelete", function () {
                var dialog = new nova.widgets.Dialog("dialogDelete");
                dialog.title = "Delete Confirm";
                dialog.content = "Are you sure you want to delete this post?";
                dialog.width = 0.8;
                dialog.height = 200;
                dialog.buttons = {
                    "Delete": function () {
                        new DbService().deleteBlog(editingBlog.id, function () {
                            new nova.widgets.Toast("The post was deleted.").show();
                            nova.application.goBack();
                        });
                    },
                    "Cancel": function () {
                        dialog.close();
                    }
                };
                dialog.closed = function () {
                    nova.application.currentPage.backbuttonHandlers.pop();
                };
                nova.application.currentPage.backbutton(function () {
                    dialog.close();
                });
                dialog.show();
            });
        });
    })();
</script>